<?php


namespace App\Services;


class CommonService
{
    const API_SECRET_KEY = 'sdksdksdcfsd';//接口加密秘钥

    const HTTP_CODE_FAIL = 100;//失败
    const HTTP_CODE_REFUND = 101;//退款余额不足
    const HTTP_CODE_SUCCESS = 200;//成功
    const HTTP_ANTCHAIN_CODE_SUCCESS = 0;//成功
    const HTTP_CODE_NOT_LOGIN = 300;//未登录
    const HTTP_CODE_BIND_MOBILE = 400;//绑定手机号
    const HTTP_CODE_NOT_AUTH = 500;//无权限
    const HTTP_DOCKING_CODE_NOT_AUTH = 2001;//未登录授权

    const IS_DELETE_NOT = 0;//未删除
    const IS_DELETE_YES = 1;//已删除

    const GOODS_IS_DELETE_NOT = 2;//未删除
    const GOODS_IS_DELETE_YES = 1;//已删除

    const USER_STATUS_NOT = 0;//非正常/冻结
    const USER_STATUS_YES = 1;//正常

    const SHOP_ENABLE = 1;//正常
    const SHOP_DISABLE = 2;//禁用
    const SHOP_CHECK = 3;//审核拒绝

    //账号级别
    const SALE_ALL = 1;//总账号
    const SALE_SON = 2;//子账号

    const PAGESIZE = 10;//分页数量

    const NOTICE_PC_URL_SCAN_LOGIN = '/Home/getUser';//PC支付宝扫码登录回调地址

    const NOTICE_XXZ_URL_AUTHORIZATION = '/Alipay/Notice/authorizationNotify';//小程序实人认证回调地址
    const NOTICE_XXZ_URL_PRE_AUTH = '/Alipay/Notice/preAuthNotify';//小程序预授权回调地址
    const NOTICE_XXZ_URL_PRE_PAY = '/Alipay/Notice/payNotify';//小程序预授权转支付回调地址
    const NOTICE_XXZ_URL_DEPOSIT = '/Alipay/Notice/deductDepositNotify';//扣除押金
    const NOTICE_XXZ_URL_HUABEI_PAY = '/Alipay/Notice/huabeiNotify';//小程序花呗支付回调地址
    const NOTICE_XXZ_URL_CONTRACT = '/Alipay/Notice/esignNotify';//小程序下单合同回调地址
    const NOTICE_XXZ_URL_PAY = '/Alipay/Notice/prepaymentNotify';//小程序主动支付回调地址
    const NOTICE_XXZ_URL_BUYOUT = '/Alipay/Notice/orderBuyoutNotify';//买断支付回调地址
    const NOTICE_SUPPLIER_URL_RECHARGE = '/Supplier/Notice/rechargeNotify';//商户充值回调地址
    const NOTICE_SUPPLIER_URL_RECHARGES = '/Supplier/Notice/rechargeNotifys';//商户采购金额充值回调地址
    const NOTICE_XXZ_URL_ANTCHAIN = '/Alipay/Notice/antchainContractNotify';//智能合同回调地址
    const NOTICE_ORDER_INSURANCE_URL_PAY = '/Alipay/Notice/orderInsuranceNotify';//小程序碎屏险购买回调地址

    const AUTH_FACE_URL = '/Alipay/Auth/checkPersonAuthUrl';//实人认证查询跳转-e签宝
    const NOTICE_AUTH_FACE_URL = '/Alipay/Notice/faceAuthNotice';//唤起实人认证回调地址-e签宝
    const NOTICE_AUTH_FACE_URL_SIGN = '/Alipay/Notice/faceAuthSignNotice';//唤起实人认证回调地址-e签宝
    const NOTICE_XXZ_URL_BOOl_AUTH_USER = '/Admin/Notice/esignBoolUserAuthNotify';//布尔信息授权书回调地址

    const NOTICE_XXZ_URL_AUTH_USER = '/Admin/Notice/esignUserAuthNotify';//个人征信授权书回调地址

    const NOTICE_XXZ_URL_AUTH_USER_Call = '/Admin/Notice/esignUserAuthCallNotify';//2024用户授权书协议回调地址

    const NOTICE_XXZ_URL_SLIENCE = '/Admin/Notice/esignSlienceNotify';//用户授权协议回调地址
    const NOTICE_XXZ_URL_COMPANY = '/Admin/Notice/esignCompanyNotify';//融资租赁委托担保合同回调地址

    const NOTICE_WX_SUNING_PAY = '/Wechat/Notice/prepaymentNotify';//微信小程序苏宁支付回调地址
    const NOTICE_WX_URL_CONTRACT = '/Wechat/Notice/esignNotify';//微信小程序下单合同回调地址

    const NOTICE_SUPPLIER_URL_CONTRACT = '/Supplier/Notice/esignNotify';//微信小程序下单合同回调地址

    const NOTICE_AUTH_WXFACE_URL = '/Wechat/Notice/faceAuthNotice';//唤起实人认证回调地址-e签宝

    const NOTICE_BAO_PAY = '/Wechat/Notice/prepaymentBaoNotify';//宝付回调地址

    //配置type
    const COMPANY_CREDIT = 1;//陕西钧信恒益融资担保有限责任公司签章资料

    public static function messageList(){
        return[
            '100'=>'失败',
            '200'=>'成功',
            '300'=>'未登录',
        ];
    }

    public static function getMEssage($code){
        return isset(self::messageList()[$code]) ? self::messageList()[$code] : '';
    }
    /**
     * 生成时间戳
     * @return type
     */
    public static function getTransid(){
        return strtotime(date('Y-m-d H:i:s',time()));
    }
    /**
     * 生成四位随机数
     * @return type
     */
    public static function getRand4(){
        return rand(1000,9999);
    }
    /**
     * 生成四位随机数
     * @return type
     */
    public static function getTime(){
        return date('Y-m-d H:i:s',time());
    }

    /**
     * 排序输出k=v&k1=v1.....格式
     * @param type $DArray
     * @return type
     */
    public static function SortAndOutString($DArray)
    {
        $TempData = array();
        foreach ($DArray As $Key => $Value){
            if(!self::isBlank($Value)){
                $TempData[$Key] = $Value;
            }
        }
        ksort($TempData);//排序
        return http_build_query($TempData);
    }

    /**
     * 判断是否空值
     * @param type $Strings
     * @return boolean
     */
    public static function isBlank($Strings){
        $Strings = trim($Strings);
        if((empty($Strings)||($Strings == null))&&(strlen($Strings) <= 0)){
            return true;
        }else{
            return FALSE;
        }
    }

    /**
     * 删除数组元素
     * @param type $data
     * @param type $key
     * @return type
     */
    public static function array_remove($data, $key){
        if(!array_key_exists($key, $data)){
            return $data;
        }
        $keys = array_keys($data);
        $index = array_search($key, $keys);
        if($index !== FALSE){
            array_splice($data, $index, 1);
        }
        return $data;
    }
    /**
     * 获取信封中的key值
     * @param type $Strings
     * @return type
     * @throws Exception
     */
    public static function getAesKey($Strings){
        $KeyArray = explode("|",$Strings);
        if(count($KeyArray) == 2){
            $KeyArray[1]=trim($KeyArray[1]);
            if(!empty($KeyArray[1])){
                return $KeyArray[1];
            }else{
                throw new Exception("Key is Null!");
            }
        }else{
            throw new Exception("Data format is incorrect!");
        }
    }
}
